using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace MyMvc.Model.Models.Mapping
{
    public class AddFileMap : EntityTypeConfiguration<AddFile>
    {
        public AddFileMap()
        {
            // Primary Key
            this.HasKey(t => new { t.ID, t.ArticleID, t.FileID });

            // Properties
            this.Property(t => t.ID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(t => t.ArticleID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.FileID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("AddFile");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.ArticleID).HasColumnName("ArticleID");
            this.Property(t => t.FileID).HasColumnName("FileID");

            // Relationships
            this.HasRequired(t => t.File)
                .WithMany(t => t.AddFiles)
                .HasForeignKey(d => d.FileID);

        }
    }
}
